package models

import anorm._
import play.api.db.DB
import scala.collection.immutable.List
import play.api.Play.current


/**
 * Created by bobr on 11/19/14.
 */


class Boundary(aId:Int, aName:String, aLvl:Int, aParent:Int, aGeom:String) {
  val id = aId
  val name = aName
  val lvl = aLvl
  val parent = aParent
  val geom = aGeom
}
object Boundary {
  def getKml: List[Boundary] = {
    DB.withConnection { implicit conn =>
      val selectGeom: anorm.SqlQuery = SQL("""select id, name, lvl, parent, ST_AsKML(geom) as geom from boundary order by lvl;""")
      val data = selectGeom().map(row =>
        new Boundary(row[Int]("id"), row[String]("name"), row[Int]("lvl"), row[Int]("parent"), row[String]("geom"))
      ).toList
      return data
    }
  }
}

class ProtectedAreas(aId:Int, aName:String, aLvl:Int, aCategory:Int, aGeom:String) {
  val id = aId
  val name = aName
  val lvl = aLvl
  val category = aCategory
  val geom = aGeom
}

object ProtectedAreas {
  def getKml: List[ProtectedAreas] = {
    DB.withConnection { implicit conn =>
      val selectGeom = SQL("""select id, name, lvl, category, ST_AsKML(geom) as geom from oopt order by id;""")
      val data = selectGeom().map(row =>
        new ProtectedAreas(row[Int]("id"), row[String]("name"), row[Int]("lvl"), row[Int]("category"),row[String]("geom"))
      ).toList
      return data
    }
  }
}

class RedBook(aName:String, aDate: String, aGeom:String) {
  val name = aName
  val date = aDate
  val geom = aGeom
}

object RedBook {
  def getKml: List[RedBook] = {
    DB.withConnection { implicit conn =>
      val selectGeom = SQL("""select name, date, ST_AsKML(geom) as geom from redbook order by name;""")
      val data = selectGeom().map(row =>
        new RedBook(row[String]("name"), row[String]("date"),row[String]("geom"))
      ).toList
      return data
    }
  }
}